"""
检查数据库中用户的权限配置
"""
import asyncio
from motor.motor_asyncio import AsyncIOMotorClient
from app.core.config import settings

async def check_users():
    # 连接数据库
    client = AsyncIOMotorClient(settings.MONGODB_URL)
    db = client[settings.MONGODB_DATABASE]
    
    # 查询所有用户
    users = await db.users.find().to_list(length=None)
    
    print("数据库中的用户:")
    for user in users:
        print(f"ID: {user['_id']}")
        print(f"用户: {user.get('name')} ({user.get('email')})")
        print(f"用户名: {user.get('username')}")
        print(f"角色: {user.get('roles', [])}")
        print(f"权限: {user.get('permissions', [])}")
        
        # 检查是否有version:read权限
        permissions = user.get('permissions', [])
        has_version_read = 'version:read' in permissions or '*' in permissions
        print(f"是否有version:read权限: {has_version_read}")
        print("---")
    
    client.close()

if __name__ == "__main__":
    asyncio.run(check_users())